import geolocation from '@system.geolocation';
import router from '@system.router';
import prompt from '@system.prompt';
export default {
    data: {
        userloginname:'',
        userpassword:''
    },
    change(e){
        this.userloginname=e.value;
    },
    change1(e){
        this.userpassword=e.value;
    },
    fankui:async function(){
//        验证用户信息是否已经登录过
        var actionData = {};
        actionData.userName = this.userloginname;
        actionData.userPassword = this.userpassword;

        var action = {};

        //添加service所在的包名
        action.bundleName = 'com.example.myapplication4';

        //添加service的类名
        action.abilityName = 'com.example.myapplication4.DemoService';

        //添加messageCode ，用于区分其他的action
        action.messageCode = 150;

        //添加数据
        action.data = actionData;

        //跳转的activity的类型，0代表service
        action.abilityType = 0;

        //最重要的一步：跳转
        var str = await FeatureAbility.callAbility(action);

        //下面是处理 java FA 返回的数据
        var result = JSON.parse(str);
        console.log(result.ans);

        //    this.id=result.id;
        if(result.ans=="已注册过"){
            prompt.showToast({
                message: '验证成功',
                duration: 1000,
            });
            router.push({
                uri: 'pages/firstpage/firstpage',
            });
        }else if(result.ans=="还没注册"){
            prompt.showToast({
                message: '验证失败',
                duration: 1000,
            });
            this.userloginname="";
            this.userpassword="";
        }
    },
    adduser(){
        router.push({
            uri: 'pages/homepage/useradd/useradd',
        });
    },
//    getLocaton(){
//        var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
//        geolocation.getCurrentLocation(requestInfo).then((result) => {
//            console.log('current location: ' + JSON.stringify(result.data));
//        });
//    },
//    getLocation(){
//
//       console.log("aaaa");
//       console.log("aabb");
//    }
}
